package com.bigbirdmed.cloud.common.core.page;


import com.google.common.collect.Lists;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;

import java.util.List;

/**
 * @author Toomth
 * @date 2021/4/12 16:59
 * @explain
 */
@Data
@AllArgsConstructor
public class PaginationOutput<T> {

	private static final long serialVersionUID = 1L;
	public PaginationOutput() {
		this.size = 10L;
		this.current = 1L;
		this.isAsc = true;
		this.rows = Lists.newArrayList();
	}
	public PaginationOutput(long current, long size) {
		this.size = 10L;
		this.current = 1L;
		this.isAsc = true;
		this.rows = Lists.newArrayList();
		if (current > 1L) {
			this.current = current;
		}

		this.size = size;
	}

	public PaginationOutput(int current, int size, String orderByField) {
		this((long) current, (long) size);
		this.setOrderByField(orderByField);
	}
	public PaginationOutput(int current, int size, String orderByField, boolean isAsc) {
		this(current, size, orderByField);
		this.setAsc(isAsc);
	}


	@ApiModelProperty(value = "顺序")
	private List<String> ascs;
	@ApiModelProperty(value = "倒序")
	private List<String> descs;
	@ApiModelProperty(value = "排序")
	private boolean isAsc;
	@ApiModelProperty(value = "排序字段")
	private String orderByField;

	@ApiModelProperty(value = "当前页")
	private long current;

	@ApiModelProperty(value = "列表长度")
	private long size;

	@ApiModelProperty(value = "列表内容")
	private List<T> rows;

	@ApiModelProperty(value = "总数")
	private long total;


	public long getPages() {
		if (this.size == 0L) {
			return 0L;
		} else {
			long pages = (this.total - 1L) / this.size;
			++pages;
			return pages;
		}
	}
}
